package com.whfc.wxmp.api.mach.v1.service.impl;

import com.github.pagehelper.PageInfo;
import com.whfc.common.result.ListData;
import com.whfc.common.result.PageData;
import com.whfc.common.util.PageUtil;
import com.whfc.fuum.service.SysDeptService;
import com.whfc.mach.dto.AppMachDataStatDTO;
import com.whfc.mach.dto.MachDayDataDTO;
import com.whfc.mach.dto.report.AppMachReportDTO;
import com.whfc.mach.service.AppReportService;
import com.whfc.wxmp.api.mach.v1.service.WxmpMachReportService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @author sun_guodong
 * @description
 * @date 2020-12-14
 */
@Service
public class WxmpMachReportServiceImpl implements WxmpMachReportService {

    @DubboReference(interfaceClass = SysDeptService.class, version = "1.0.0")
    private SysDeptService sysDeptService;

    @DubboReference(interfaceClass = AppReportService.class, version = "1.0.0")
    private AppReportService appReportService;

    @Override
    public PageData<AppMachReportDTO> dayReportDataList(Integer deptId, Integer pageNum, Integer pageSize) {
        List<Integer> deptIds = sysDeptService.getDescendantDeptIdList(deptId);
        return appReportService.getDayReportDataList(deptIds, null, null, pageNum, pageSize);
    }

    @Override
    public PageData<AppMachReportDTO> getWeekReportDataList(Integer deptId, Integer pageNum, Integer pageSize) {
        return appReportService.getWeekReportDataList(deptId, pageNum, pageSize, null, null);
    }

    @Override
    public PageData<AppMachReportDTO> getMonthReportDataList(Integer deptId, Integer pageNum, Integer pageSize) {
        return appReportService.getMonthReportDataList(deptId, pageNum, pageSize, null, null);
    }

    @Override
    public AppMachDataStatDTO dayReportStat(Integer deptId, Date date) {
        List<Integer> deptIds = sysDeptService.getDescendantDeptIdList(deptId);
        if (deptIds == null || deptIds.size() == 0) {
            return new AppMachDataStatDTO();
        }
        return appReportService.reportStat(deptIds, date, date);
    }

    @Override
    public AppMachDataStatDTO weekReportStat(Integer deptId, Date startDate, Date endDate) {
        List<Integer> deptIds = sysDeptService.getDescendantDeptIdList(deptId);
        if (deptIds == null || deptIds.size() == 0) {
            return new AppMachDataStatDTO();
        }
        return appReportService.reportStat(deptIds, startDate, endDate);
    }

    @Override
    public ListData<MachDayDataDTO> dayReport(Integer deptId, Date date) {
        List<Integer> deptIds = sysDeptService.getDescendantDeptIdList(deptId);
        if (deptIds == null || deptIds.size() == 0) {
            return PageUtil.pageData(PageInfo.of(Collections.EMPTY_LIST));
        }
        return appReportService.dayReport(deptIds, date, date);
    }

    @Override
    public ListData<MachDayDataDTO> weekReport(Integer deptId, Date startDate, Date endDate) {
        List<Integer> deptIds = sysDeptService.getDescendantDeptIdList(deptId);
        if (deptIds == null || deptIds.size() == 0) {
            return PageUtil.pageData(PageInfo.of(Collections.EMPTY_LIST));
        }
        return appReportService.dayReport(deptIds, startDate, endDate);
    }
}
